#include "stdafx.h"
#include "BLDC.h"
extern unsigned int MXCurrentList[1000];
extern unsigned int MXCurrentListCount;
extern unsigned int MuXianCurrent;

void __attribute__((__interrupt__,auto_psv)) _CNInterrupt(void)
{
	unsigned int i,xx;
	unsigned long x=0;
	if(BLDC_QiDong<500)
	{
		BLDC_QiDong++;		
	}
	if(BLDC_QiDong==500)
	{
		BLDC_oldHallValue=BLDC_HallValue;
	}
	if(MXCurrentListCount==0)
		MuXianCurrent=388;
	else
	{
		for(i=0;i<MXCurrentListCount;i++)
			x += (unsigned long)MXCurrentList[i];
		xx=__builtin_divud(x,MXCurrentListCount);
		MuXianCurrent=xx;
		MXCurrentListCount=0;
	}
	BLDC_Timer[BLDC_TimerIndex]=TMR2;
	TMR2=0;
	BLDC_TimerIndex++;
	if(BLDC_TimerIndex>=60)
		BLDC_TimerIndex=0;
	BLDC_GetHall();
	BLDC_ChangePhasic();	
	_CNIF=0;
}
